'''
Created on Apr 14, 2012
TestCase ID: Ecom_5008
Description : Kiem thu chuc nang tim kiem khoa hoc
@author: Vu Dao
'''
import unittest
import HTMLTestRunner
from Functions.globalFunc import readData, preCondition, endCondition
from Functions.loginPageFunc import login
from Functions.coursesFunc import clickOnCourse, searchCourse,\
    verifyACourseExist
import time
username = readData("username")
password = readData("password")
courseName = readData("courseName")

class Ecom_5008(unittest.TestCase):


    def setUp(self):
        print "Buoc 1: Mo website"
        preCondition(self)

    def test_Ecom_5008(self):
        print "Buoc 2: Dang nhap vao website"
        login(self,username, password)
        
        print "Buoc 3: Click vao Course"
        clickOnCourse(self)
        time.sleep(5)
        print "Buoc 4: Nhap ten khoa hoc da co vao o filter"
        searchCourse(self,courseName)
        
        print "buoc 5: Kiem tra khoa hoc co ton tai hay khong"
        self.assertTrue(verifyACourseExist(self,courseName), "Failed: Khoa hoc khong ton tai")
        print "Passed: Khoa hoc ton tai"

    def tearDown(self):
        print "Buoc 6: Dong website"
        endCondition(self)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5008)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tim kiem khoa hoc'
                    )
    runner.run(suite)

